package com.kxmall.web.controller.huishou;

import java.util.List;
import java.util.Arrays;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;
import com.kxmall.huishou.domain.vo.HsWasteNewsVo;
import com.kxmall.huishou.domain.bo.HsWasteNewsBo;
import com.kxmall.huishou.service.IHsWasteNewsService;
import com.kxmall.common.core.page.TableDataInfo;

/**
 * 环保科普信息
 *
 * @author kxmall
 * @date 2023-11-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/huishou/wasteNews")
public class HsWasteNewsController extends BaseController {

    private final IHsWasteNewsService iHsWasteNewsService;

    /**
     * 查询环保科普信息列表
     */
    @SaCheckPermission("huishou:wasteNews:list")
    @GetMapping("/list")
    public TableDataInfo<HsWasteNewsVo> list(HsWasteNewsBo bo, PageQuery pageQuery) {
        return iHsWasteNewsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出环保科普信息列表
     */
    @SaCheckPermission("huishou:wasteNews:export")
    @Log(title = "环保科普信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HsWasteNewsBo bo, HttpServletResponse response) {
        List<HsWasteNewsVo> list = iHsWasteNewsService.queryList(bo);
        ExcelUtil.exportExcel(list, "环保科普信息", HsWasteNewsVo.class, response);
    }

    /**
     * 获取环保科普信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("huishou:wasteNews:query")
    @GetMapping("/{id}")
    public R<HsWasteNewsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iHsWasteNewsService.queryById(id));
    }

    /**
     * 新增环保科普信息
     */
    @SaCheckPermission("huishou:wasteNews:add")
    @Log(title = "环保科普信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HsWasteNewsBo bo) {
        return toAjax(iHsWasteNewsService.insertByBo(bo));
    }

    /**
     * 修改环保科普信息
     */
    @SaCheckPermission("huishou:wasteNews:edit")
    @Log(title = "环保科普信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HsWasteNewsBo bo) {
        return toAjax(iHsWasteNewsService.updateByBo(bo));
    }

    /**
     * 删除环保科普信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("huishou:wasteNews:remove")
    @Log(title = "环保科普信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iHsWasteNewsService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
